﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AuctionHelper.Entity;
using AuctionHelper.Core;

namespace AuctionHelper.Business
{
    /// <summary>
    /// 拍卖业务类
    /// </summary>
    internal class AuctionBLL
    {
        /// <summary>
        /// 设置搜索条件
        /// </summary>
        /// <param name="script"></param>
        internal static void SetSearchFilter(Auction auction)
        {
            //设置职业
            ElementBLL.SetListItem(auction.Elements.SingleOrDefault(e => e.Name == "ListItem_Class") as ListItem);

            //设置物品品质
            ElementBLL.SetListItem(auction.Elements.SingleOrDefault(e => e.Name == "ListItem_ItemQuanity") as ListItem);

            //设置装备部位
            ElementBLL.SetListItem(auction.Elements.SingleOrDefault(e => e.Name == "ListItem_EquipmentPosition") as ListItem);

            //设置装备类别
            ElementBLL.SetListItem(auction.Elements.SingleOrDefault(e => e.Name == "ListItem_EquipmentType") as ListItem);
            ElementBLL.SetScrollListItem(auction.Elements.SingleOrDefault(e => e.Name == "ScrollListItem_EquipmentType") as ScrollListItem);

            //设置等级
            ElementBLL.SetText(auction.Elements.SingleOrDefault(e => e.Name == "Text_Level") as Text);

            //设置过滤条件
            ElementBLL.SetScrollListItem(auction.Elements.SingleOrDefault(e => e.Name == "ScrollListItem_Filter1") as ScrollListItem);
            ElementBLL.SetScrollListItem(auction.Elements.SingleOrDefault(e => e.Name == "ScrollListItem_Filter2") as ScrollListItem);
            ElementBLL.SetScrollListItem(auction.Elements.SingleOrDefault(e => e.Name == "ScrollListItem_Filter3") as ScrollListItem);

            //设置过滤值
            ElementBLL.SetText(auction.Elements.SingleOrDefault(e => e.Name == "Text_FilterValue1") as Text);
            ElementBLL.SetText(auction.Elements.SingleOrDefault(e => e.Name == "Text_FilterValue2") as Text);
            ElementBLL.SetText(auction.Elements.SingleOrDefault(e => e.Name == "Text_FilterValue3") as Text);

            //设置竞标最大金额
            ElementBLL.SetText(auction.Elements.SingleOrDefault(e => e.Name == "Text_MaxBidGold") as Text);
        }

        /// <summary>
        /// 搜索
        /// </summary>
        internal static void Search(Auction auction)
        {
            var button = auction.Elements.SingleOrDefault(e => e.Name == "Button_Search") as Button;
            ElementBLL.ButtonClick(button);
         }

        /// <summary>
        /// 搜索结果排序
        /// </summary>
        /// <param name="auction"></param>
        internal static void SearchReSort(Auction auction)
        {
            var buttonType = string.Format("Button_{0}ReSort", auction.IsPriceReSort ? "Dps" : "Price");
            var button = auction.Elements.SingleOrDefault(e => e.Name == buttonType) as Button;
            ElementBLL.ButtonClick(button);
            ElementBLL.ButtonClick(button);
        }

        /// <summary>
        /// 获取搜索结果
        /// </summary>
        /// <param name="auction"></param>
        internal static List<Equipment> GetSearchResult(Auction auction)
        {
            var imageFilePath = ConfigHelper.GetImageFilePath();
            CaptureHelper.GetScreen(imageFilePath);
            return null;
        }

        
    }
}
